import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 导入 bootstrap 样式表
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'

// 导入全局样式表
import './index.css'
// 导入路由实例
import router from './router.js'
import axios from "axios"

axios.defaults.baseURL = 'http://39.101.74.44:3007'
// 配置拦截器并设置请求头
let loading
// 请求拦截器
axios.interceptors.request.use(config => {
    config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    const tokenStr = localStorage.getItem('token')
    if (tokenStr) config.headers['Authorization'] = tokenStr
    loading = app.config.globalProperties.$loading({
        fullcreen: true,
        lock: true
    })
    return config
})
// 响应拦截器
axios.interceptors.response.use(response => {
    loading.close()
    return response
})

// 创建 app 实例
const app = createApp(App)
app.use(ElementPlus)
// 挂载路由实例
app.use(router)

app.config.globalProperties.$http = axios


app.mount('#app')
